import { Component, OnInit } from '@angular/core';

declare var BMapGL: any;

@Component({
  selector: 'app-test',
  templateUrl: './test.component.html',
  styleUrls: ['./test.component.less']
})
export class ExampleComponent implements OnInit {
  map?: any;

  ngOnInit() {
    console.log();
  }

  newMap() {
    this.map = new BMapGL.Map('maps');
    this.map.centerAndZoom(new BMapGL.Point(116.404, 39.915), 15);
    this.map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
    this.map.addEventListener('click', (e: any) => {
      console.log(`点击的经纬度：${e.latlng.lng}, ${e.latlng.lat}`);
      var mercator = this.map.lnglatToMercator(e.latlng.lng, e.latlng.lat);
      console.log(`点的墨卡托坐标：${mercator[0]}, ${mercator[1]}`);
      console.log('e');
      try {
        console.log(JSON.stringify(e));
      } catch {
        console.log('JSON.stringify(e)没法执行');
      }

      try {
        console.log(JSON.parse(e));
      } catch {
        console.log('console.log(JSON.parse(e));');
      }

      console.log('e');
      console.log(e);
    });
  }
}
